1. Field of the Invention
The present invention relates to a coding method for coding digital data broken down into a plurality of components and a digital data coding apparatus for performing the coding method.
2. Description of the Related Art
Data to be processed in a digital audio unit is recorded in a compressed form to allow more data to be recorded on a recording medium. To compress data, time-series audio data is converted to data on the frequency axis, then divided into a plurality of blocks according to the frequency. This digital audio data of each block is coded in accordance with a number of bits assigned to each block. Usually, a larger number of bits are assigned to a lower frequency block.
FIG. 7 is a block diagram showing the configuration of a coding apparatus for coding digital data. Input data X(n) is obtained by performing Fourier transformation on audio data with the result then plotted on the frequency axis. FIG. 8 shows an example. In FIG. 8, one block of data is divided into eight bands: B1 to B8. For each band of data X(n), there are two hearing levels: one is the lowest audible level L1 at which humans can hear a sound and the masking level L2 at which humans cannot hear a sound because the sound is masked by another sound. Humans can hear only the sounds exceeding both levels L1 and L2. A coding apparatus assigns a specific number of bits to each of bands, B1 to B8, according to the lowest audible level L1 or the masking level L2, whichever is higher, and the difference between the signal level L0 of each band (B1 to B8). This makes it possible to compress audio data X(n) without deterioration of the quality of the sound when it is played back later.
Data X(n) is stored continuously to a register 1, one block at a time, and is read from it, as band data Am(n)representing the level of each band in the block. A number-of-bits data generation circuit 2 assigns a number of bits according to the content of band data Am(n) and generates number-of-bits data Wm(n) specifying the number of bits for coding band data Am(n). The value of this number-of-bits data Wm(n) depends on the difference between the lowest audible level L1 or the masking level L2, whichever is higher, and the signal level L0 of each band (B1 to B8). That is, the value is small for a band whose difference is small; the value is large for a band whose difference is large.
When coding band data Am(n), a correction data generation circuit 3 calculates the total number of bits required for a block based on number-of-bits data Wm(n). Then, based on the difference between the calculated total number of bits and the target number of bits, the correction circuit calculates how many bits must be reduced to keep the total number of bits of a block below a desired number of bits. The correction circuit generates correction data C(n) representing the number of bits to be reduced from the number-of-bits data Wm(n). Based on the correction data C(n), a number-of-bits data correction circuit 4 corrects the number-of-bits data Wm(n) which was output from the number-of-bits data generation circuit 2 and generates number-of-correction-bits data wm(n).
A coding circuit 5 codes the band data Am(n) read from register 1 according to the number-of-correction-bits data wm(n) and generates compressed data Y(n) whose number of bits has been reduced. That is, the compressed data Y(n) output from the coding circuit 5 is created based on the number-of-correction-bits data wm(n) corrected by the correction data C(n). Thus, the number of bits of the compressed data Y(n) is smaller than the target number of bits of a block.
When the total number of bits of a block exceeds the target number of bits, the above coding apparatus reduces one bit from each of bands, B1 to B8. This means that, when one bit is reduced from each of bands B1 to B8, a total of eight bits are reduced. The difference between the total number of bits and the target number of bits becomes too large. For example, even when the total number of bits is only one bit larger than the target number of bits, one bit is reduced from each of bands B1 to B8. This results in the total number of bits being seven bits less than the target number of bits; these seven bits, although available for use for coding, are not used. The likelihood that these wasteful bits will be generated increases along with the number of bands.
The present invention reduces the number of wasted bits and makes the number of bits as close to the target number of bits as possible.
There is provided a digital data coding method for coding one block of digital data at a time, in which each block is composed of a plurality of digital data values and each digital data value represents a value of a corresponding component. The digital data coding method comprises: a first step for calculating specific weight data for each component; a second step for assigning a number of bits to each component according to the weight data; a third step for calculating a total value of the number of bits of one block, the number of bits being assigned in the second step; a fourth step for comparing between the total value of the number of bits of one block calculated in the third step with a predetermined aim value; and a fifth step for increasing or decreasing the weight data calculated in the first step according to the comparison in the fourth step, wherein by repeating the first step to the fifth step, the total number of bits of one block is converged into a predetermined range.
According to the present invention, weight data and the number of bits representing the number of bits of data to be coded are independent of each other. This makes it possible to use more bits to represent the weight data than to represent the number of bits used to represent the number of bits of data to be coded, thus allowing the weight data to be increased or decreased more flexibly than the number of bits. Therefore, by assigning the number of bits based on the weight data, the number of bits may be selectively increased or decreased for each band.